home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright 1994, Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- * the contents of this file may not be disclosed to third parties, copied or
- * duplicated in any form, in whole or in part, without the prior written
- * permission of Silicon Graphics, Inc.
- *
- * RESTRICTED RIGHTS LEGEND:
- * Use, duplication or disclosure by the Government is subject to restrictions
- * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- * rights reserved under the Copyright Laws of the United States.
- */
- /*
- * 1992 David G Yu -- Silicon Graphics Computer Systems
- */
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <math.h>
- #include <X11/Xlib.h>
- #include <X11/keysym.h>
- #include <GL/glx.h>
- #include <GL/gl.h>
-
- static int useRGB = 1;
- static int useLighting = 1;
- static int useFog = 0;
- static int useDB = 1;
- static int useLogo = 0;
- static int useQuads = 1;
-
- #define GREY 0
- #define RED 1
- #define GREEN 2
- #define BLUE 3
- #define CYAN 4
- #define MAGENTA 5
- #define YELLOW 6
- #define BLACK 7
-
- static float materialColor[8][4] = {
- { 0.8, 0.8, 0.8, 1.0 },
- { 0.8, 0.0, 0.0, 1.0 },
- { 0.0, 0.8, 0.0, 1.0 },
- { 0.0, 0.0, 0.8, 1.0 },
- { 0.0, 0.8, 0.8, 1.0 },
- { 0.8, 0.0, 0.8, 1.0 },
- { 0.8, 0.8, 0.0, 1.0 },
- { 0.0, 0.0, 0.0, 0.4 },
- };
-
- static float lightPos[4] = { 2.0, 4.0, 2.0, 1.0 };
- static float lightDir[4] = { -2.0, -4.0, -2.0, 1.0 };
- static float lightAmb[4] = { 0.2, 0.2, 0.2, 1.0 };
- static float lightDiff[4] = { 0.8, 0.8, 0.8, 1.0 };
- static float lightSpec[4] = { 0.4, 0.4, 0.4, 1.0 };
-
- static float groundPlane[4] = { 0.0, 1.0, 0.0, 1.499 };
- static float backPlane[4] = { 0.0, 0.0, 1.0, 0.899 };
-
- static float fogColor[4] = { 0.0, 0.0, 0.0, 0.0 };
- static float fogIndex[1] = { 0.0 };
-
- static unsigned char shadowPattern[128] = {
- 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55, /* 50% Grey */
- 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55,
- 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55,
- 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55,
- 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55,
- 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55,
- 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55,
- 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55,
- 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55,
- 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55,
- 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55,
- 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55,
- 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55,
- 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55,
- 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55,
- 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55
- };
-
- static unsigned char sgiPattern[128] = {
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* SGI Logo */
- 0xff, 0xbd, 0xff, 0x83, 0xff, 0x5a, 0xff, 0xef,
- 0xfe, 0xdb, 0x7f, 0xef, 0xfd, 0xdb, 0xbf, 0xef,
- 0xfb, 0xdb, 0xdf, 0xef, 0xf7, 0xdb, 0xef, 0xef,
- 0xfb, 0xdb, 0xdf, 0xef, 0xfd, 0xdb, 0xbf, 0x83,
- 0xce, 0xdb, 0x73, 0xff, 0xb7, 0x5a, 0xed, 0xff,
- 0xbb, 0xdb, 0xdd, 0xc7, 0xbd, 0xdb, 0xbd, 0xbb,
- 0xbe, 0xbd, 0x7d, 0xbb, 0xbf, 0x7e, 0xfd, 0xb3,
- 0xbe, 0xe7, 0x7d, 0xbf, 0xbd, 0xdb, 0xbd, 0xbf,
- 0xbb, 0xbd, 0xdd, 0xbb, 0xb7, 0x7e, 0xed, 0xc7,
- 0xce, 0xdb, 0x73, 0xff, 0xfd, 0xdb, 0xbf, 0xff,
- 0xfb, 0xdb, 0xdf, 0x87, 0xf7, 0xdb, 0xef, 0xfb,
- 0xf7, 0xdb, 0xef, 0xfb, 0xfb, 0xdb, 0xdf, 0xfb,
- 0xfd, 0xdb, 0xbf, 0xc7, 0xfe, 0xdb, 0x7f, 0xbf,
- 0xff, 0x5a, 0xff, 0xbf, 0xff, 0xbd, 0xff, 0xc3,
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
- };
-
- static float cube_vertexes[6][4][4] = {
- { { -1.0, -1.0, -1.0, 1.0 },
- { -1.0, -1.0, 1.0, 1.0 },
- { -1.0, 1.0, 1.0, 1.0 },
- { -1.0, 1.0, -1.0, 1.0 } },
-
- { { 1.0, 1.0, 1.0, 1.0 },
- { 1.0, -1.0, 1.0, 1.0 },
- { 1.0, -1.0, -1.0, 1.0 },
- { 1.0, 1.0, -1.0, 1.0 } },
-
- { { -1.0, -1.0, -1.0, 1.0 },
- { 1.0, -1.0, -1.0, 1.0 },
- { 1.0, -1.0, 1.0, 1.0 },
- { -1.0, -1.0, 1.0, 1.0 } },
-
- { { 1.0, 1.0, 1.0, 1.0 },
- { 1.0, 1.0, -1.0, 1.0 },
- { -1.0, 1.0, -1.0, 1.0 },
- { -1.0, 1.0, 1.0, 1.0 } },
-
- { { -1.0, -1.0, -1.0, 1.0 },
- { -1.0, 1.0, -1.0, 1.0 },
- { 1.0, 1.0, -1.0, 1.0 },
- { 1.0, -1.0, -1.0, 1.0 } },
-
- { { 1.0, 1.0, 1.0, 1.0 },
- { -1.0, 1.0, 1.0, 1.0 },
- { -1.0, -1.0, 1.0, 1.0 },
- { 1.0, -1.0, 1.0, 1.0 } }
- };
-
- static float cube_normals[6][4] = {
- { -1.0, 0.0, 0.0, 0.0 },
- { 1.0, 0.0, 0.0, 0.0 },
- { 0.0, -1.0, 0.0, 0.0 },
- { 0.0, 1.0, 0.0, 0.0 },
- { 0.0, 0.0, -1.0, 0.0 },
- { 0.0, 0.0, 1.0, 0.0 }
- };
-
- static void
- usage(int argc, char **argv)
- {
- printf("\n");
- printf("usage: %s [options]\n", argv[0]);
- printf("\n");
- printf(" display a spinning cube and its shadow\n");
- printf("\n");
- printf(" Options:\n");
- printf(" -geometry window size and location\n");
- printf(" -c toggle color index mode\n");
- printf(" -l toggle lighting\n");
- printf(" -f toggle fog\n");
- printf(" -db toggle double buffering\n");
- printf(" -logo toggle sgi logo for the shadow pattern\n");
- printf(" -quads toggle use of GL_QUADS to draw the checkerboard\n");
- printf("\n");
- exit(EXIT_FAILURE);
- }
-
- static Colormap
- buildColormap(Display *dpy, Window root, XVisualInfo *vis)
- {
- Colormap cmap;
-
- if (useRGB) {
- cmap = XCreateColormap(dpy, root, vis->visual, AllocNone);
- } else {
- int mapSize = 1 << vis->depth;
- int rampSize = mapSize / 8;
- int entry;
- int i;
-
- cmap = XCreateColormap(dpy, root, vis->visual, AllocAll);
-
- for (entry = 0; entry < mapSize; ++entry)
- {
- XColor col;
- int hue = entry / rampSize;
- short val = (entry % rampSize) * (0xffff / (rampSize-1));
-
- col.pixel = entry;
- col.red = (hue==0 || hue==1 || hue==5 || hue==6) ? val : 0;
- col.green = (hue==0 || hue==2 || hue==4 || hue==6) ? val : 0;
- col.blue = (hue==0 || hue==3 || hue==4 || hue==5) ? val : 0;
- col.flags = DoRed | DoGreen | DoBlue;
-
- XStoreColor(dpy, cmap, &col);
- }
-
- for (i = 0; i < 8; ++i)
- {
- materialColor[i][0] = i*rampSize + 0.2 * (rampSize-1);
- materialColor[i][1] = i*rampSize + 0.8 * (rampSize-1);
- materialColor[i][2] = i*rampSize + 1.0 * (rampSize-1);
- materialColor[i][3] = 0.0;
- }
-
- fogIndex[0] = -0.2 * (rampSize-1);
- }
-
- return cmap;
- }
-
- static void
- setColor(int c)
- {
- if (useLighting) {
- if (useRGB) {
- glMaterialfv(GL_FRONT_AND_BACK,
- GL_AMBIENT_AND_DIFFUSE, &materialColor[c][0]);
- } else {
- glMaterialfv(GL_FRONT_AND_BACK,
- GL_COLOR_INDEXES, &materialColor[c][0]);
- }
- } else {
- if (useRGB) {
- glColor4fv(&materialColor[c][0]);
- } else {
- glIndexf(materialColor[c][1]);
- }
- }
- }
-
- static void
- drawCube(int color)
- {
- int i;
-
- setColor(color);
-
- for (i = 0; i < 6; ++i)
- {
- glNormal3fv(&cube_normals[i][0]);
- glBegin(GL_POLYGON);
- glVertex4fv(&cube_vertexes[i][0][0]);
- glVertex4fv(&cube_vertexes[i][1][0]);
- glVertex4fv(&cube_vertexes[i][2][0]);
- glVertex4fv(&cube_vertexes[i][3][0]);
- glEnd();
- }
- }
-
- static void
- drawCheck(int w, int h, int evenColor, int oddColor)
- {
- static int initialized = 0;
- static int usedLighting = 0;
- static GLuint checklist = 0;
-
- if (!initialized || (usedLighting != useLighting))
- {
- static float square_normal[4] = { 0.0, 0.0, 1.0, 0.0 };
- static float square[4][4];
- int i, j;
-
- if (!checklist)
- {
- checklist = glGenLists(1);
- }
- glNewList(checklist, GL_COMPILE_AND_EXECUTE);
-
- if (useQuads) {
- glNormal3fv(square_normal);
- glBegin(GL_QUADS);
- }
-
- for (j = 0; j < h; ++j)
- {
- for (i = 0; i < w; ++i)
- {
- square[0][0] = -1.0 + 2.0/w * i;
- square[0][1] = -1.0 + 2.0/h * (j+1);
- square[0][2] = 0.0;
- square[0][3] = 1.0;
-
- square[1][0] = -1.0 + 2.0/w * i;
- square[1][1] = -1.0 + 2.0/h * j;
- square[1][2] = 0.0;
- square[1][3] = 1.0;
-
- square[2][0] = -1.0 + 2.0/w * (i+1);
- square[2][1] = -1.0 + 2.0/h * j;
- square[2][2] = 0.0;
- square[2][3] = 1.0;
-
- square[3][0] = -1.0 + 2.0/w * (i+1);
- square[3][1] = -1.0 + 2.0/h * (j+1);
- square[3][2] = 0.0;
- square[3][3] = 1.0;
-
- if (i & 1 ^ j & 1) {
- setColor(oddColor);
- } else {
- setColor(evenColor);
- }
-
- if (!useQuads) {
- glBegin(GL_POLYGON);
- }
- glVertex4fv(&square[0][0]);
- glVertex4fv(&square[1][0]);
- glVertex4fv(&square[2][0]);
- glVertex4fv(&square[3][0]);
- if (!useQuads) {
- glEnd();
- }
- }
- }
-
- if (useQuads) {
- glEnd();
- }
-
- glEndList();
-
- initialized = 1;
- usedLighting = useLighting;
- }
- else
- {
- glCallList(checklist);
- }
- }
-
- static void
- myShadowMatrix(float ground[4], float light[4])
- {
- float dot;
- float shadowMat[4][4];
-
- dot = ground[0] * light[0] +
- ground[1] * light[1] +
- ground[2] * light[2] +
- ground[3] * light[3];
-
- shadowMat[0][0] = dot - light[0] * ground[0];
- shadowMat[1][0] = 0.0 - light[0] * ground[1];
- shadowMat[2][0] = 0.0 - light[0] * ground[2];
- shadowMat[3][0] = 0.0 - light[0] * ground[3];
-
- shadowMat[0][1] = 0.0 - light[1] * ground[0];
- shadowMat[1][1] = dot - light[1] * ground[1];
- shadowMat[2][1] = 0.0 - light[1] * ground[2];
- shadowMat[3][1] = 0.0 - light[1] * ground[3];
-
- shadowMat[0][2] = 0.0 - light[2] * ground[0];
- shadowMat[1][2] = 0.0 - light[2] * ground[1];
- shadowMat[2][2] = dot - light[2] * ground[2];
- shadowMat[3][2] = 0.0 - light[2] * ground[3];
-
- shadowMat[0][3] = 0.0 - light[3] * ground[0];
- shadowMat[1][3] = 0.0 - light[3] * ground[1];
- shadowMat[2][3] = 0.0 - light[3] * ground[2];
- shadowMat[3][3] = dot - light[3] * ground[3];
-
- glMultMatrixf((const GLfloat*)shadowMat);
- }
-
- static char *windowNameRGBDB = "shadow cube (OpenGL RGB DB)";
- static int visattrsRGBDB[] = {
- GLX_RGBA,
- GLX_DOUBLEBUFFER,
- GLX_RED_SIZE, 1,
- GLX_GREEN_SIZE, 1,
- GLX_BLUE_SIZE, 1,
- GLX_DEPTH_SIZE, 1,
- None
- };
-
- static char *windowNameRGB = "shadow cube (OpenGL RGB)";
- static int visattrsRGB[] = {
- GLX_RGBA,
- GLX_RED_SIZE, 1,
- GLX_GREEN_SIZE, 1,
- GLX_BLUE_SIZE, 1,
- GLX_DEPTH_SIZE, 1,
- None
- };
-
- static char *windowNameIndexDB = "shadow cube (OpenGL Index DB)";
- static int visattrsIndexDB[] = {
- GLX_DOUBLEBUFFER,
- GLX_BUFFER_SIZE, 4,
- GLX_DEPTH_SIZE, 1,
- None
- };
-
- static char *windowNameIndex = "shadow cube (OpenGL Index)";
- static int visattrsIndex[] = {
- GLX_BUFFER_SIZE, 8,
- GLX_DEPTH_SIZE, 1,
- None
- };
-
- static Bool
- waitForNotify(Display *dpy, XEvent *event, char *arg)
- {
- return (event->type == MapNotify) && (event->xmap.window == (Window)arg);
- }
-
- int
- main(int argc, char **argv)
- {
- Display *dpy;
- char *geometry = NULL;
- int scr;
- int *visattrs;
- XVisualInfo *vis;
- XSetWindowAttributes swa;
- int width = 300, height = 300;
- Window win;
- GLXContext ctx;
- char *name;
- XSizeHints sizehints;
- XEvent event;
- int i;
-
- GLfloat cubeXform[4][4];
-
- /* process commmand line args */
- for (i = 1; i < argc; ++i)
- {
- if (!strcmp("-geometry", argv[i]))
- {
- i++;
- geometry = argv[i];
- if (geometry == NULL) {
- usage(argc, argv);
- }
- }
- else if (!strcmp("-c", argv[i]))
- {
- useRGB = !useRGB;
- }
- else if (!strcmp("-l", argv[i]))
- {
- useLighting = !useLighting;
- }
- else if (!strcmp("-f", argv[i]))
- {
- useFog = !useFog;
- }
- else if (!strcmp("-db", argv[i]))
- {
- useDB = !useDB;
- }
- else if (!strcmp("-logo", argv[i]))
- {
- useLogo = !useLogo;
- }
- else if (!strcmp("-quads", argv[i]))
- {
- useQuads = !useQuads;
- }
- else
- {
- usage(argc, argv);
- }
- }
-
- /* open connection */
- if ((dpy = XOpenDisplay(NULL)) == NULL) {
- fprintf(stderr, "couldn't open display\n");
- exit(EXIT_FAILURE);
- }
- scr = DefaultScreen(dpy);
-
- /* choose visual */
- if (useRGB) {
- if (useDB) {
- visattrs = visattrsRGBDB;
- name = windowNameRGBDB;
- } else {
- visattrs = visattrsRGB;
- name = windowNameRGB;
- }
- } else {
- if (useDB) {
- visattrs = visattrsIndexDB;
- name = windowNameIndexDB;
- } else {
- visattrs = visattrsIndex;
- name = windowNameIndex;
- }
- }
-
- if ((vis = glXChooseVisual(dpy, scr, visattrs)) == NULL) {
- fprintf(stderr, "couldn't find visual\n");
- exit(EXIT_FAILURE);
- }
-
- /* create context */
- if ((ctx = glXCreateContext(dpy, vis, None, True)) == NULL) {
- fprintf(stderr, "couldn't create context\n");
- exit(EXIT_FAILURE);
- }
-
- /* create window */
- sizehints.flags = PPosition | PSize;
- sizehints.width = width;
- sizehints.height = height;
- sizehints.x = 0;
- sizehints.y = 0;
- if(geometry) {
- int flags, x, y, width, height;
-
- flags = XParseGeometry(geometry, &x, &y,
- (unsigned int *)&width,
- (unsigned int *)&height);
- if(WidthValue & flags) {
- sizehints.flags |= USSize;
- sizehints.width = width;
- }
- if(HeightValue & flags) {
- sizehints.flags |= USSize;
- sizehints.height = height;
- }
- if(XValue & flags) {
- if(XNegative & flags)
- x = DisplayWidth(dpy, DefaultScreen(dpy)) + x
- - sizehints.width;
- sizehints.flags |= USPosition;
- sizehints.x = x;
- }
- if(YValue & flags) {
- if(YNegative & flags)
- y = DisplayHeight(dpy, DefaultScreen(dpy)) + y
- - sizehints.height;
- sizehints.flags |= USPosition;
- sizehints.y = y;
- }
- }
- swa.colormap = buildColormap(dpy, RootWindow(dpy, scr), vis);
- swa.border_pixel = 0;
- swa.background_pixel = 0;
- swa.event_mask = KeyPressMask | StructureNotifyMask;
- win = XCreateWindow(dpy, RootWindow(dpy, scr),
- sizehints.x, sizehints.y,
- sizehints.width, sizehints.height,
- 0, vis->depth, InputOutput, vis->visual,
- CWBorderPixel | CWBackPixel | CWColormap | CWEventMask,
- &swa);
-
- XSetStandardProperties(dpy, win, name, name, None,
- argv, argc, &sizehints);
-
- XMapWindow(dpy, win);
- XIfEvent(dpy, &event, waitForNotify, (char*)win);
-
- /* bind context to window */
- glXMakeCurrent(dpy, win, ctx);
-
- /* setup context */
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glFrustum(-1.0, 1.0, -1.0, 1.0, 1.0, 3.0);
-
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- glTranslatef(0.0, 0.0, -2.0);
-
- glEnable(GL_DEPTH_TEST);
-
- if (useLighting) {
- glEnable(GL_LIGHTING);
- }
- glEnable(GL_LIGHT0);
- glLightfv(GL_LIGHT0, GL_POSITION, lightPos);
- glLightfv(GL_LIGHT0, GL_AMBIENT, lightAmb);
- glLightfv(GL_LIGHT0, GL_DIFFUSE, lightDiff);
- glLightfv(GL_LIGHT0, GL_SPECULAR, lightSpec);
- /*
- glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, lightDir);
- glLightf(GL_LIGHT0, GL_SPOT_EXPONENT, 80);
- glLightf(GL_LIGHT0, GL_SPOT_CUTOFF, 25);
- */
-
- glEnable(GL_NORMALIZE);
-
- if (useFog) {
- glEnable(GL_FOG);
- }
- glFogfv(GL_FOG_COLOR, fogColor);
- glFogfv(GL_FOG_INDEX, fogIndex);
- glFogf(GL_FOG_MODE, GL_EXP);
- glFogf(GL_FOG_DENSITY, 0.5);
- glFogf(GL_FOG_START, 1.0);
- glFogf(GL_FOG_END, 3.0);
-
- glEnable(GL_CULL_FACE);
- glCullFace(GL_BACK);
-
- glShadeModel(GL_SMOOTH);
-
- glBlendFunc(GL_ONE_MINUS_SRC_ALPHA, GL_SRC_ALPHA);
- if (useLogo) {
- glPolygonStipple((const GLubyte *)sgiPattern);
- } else {
- glPolygonStipple((const GLubyte *)shadowPattern);
- }
-
- glClearColor(0.0, 0.0, 0.0, 1);
- glClearIndex(0);
- glClearDepth(1);
-
- /* spin cube */
- while (1)
- {
- for (i = 0; i < 120; ++i)
- {
- if (XPending(dpy)) {
- XNextEvent(dpy, &event);
-
- switch (event.type) {
- case KeyPress:
- {
- KeySym ks;
- char buf[2];
-
- XLookupString(&event.xkey, buf, 2, &ks, NULL);
- switch (ks) {
- case XK_Escape:
- exit(0);
- break;
- case XK_L: case XK_l:
- useLighting = !useLighting;
- useLighting ? glEnable(GL_LIGHTING) :
- glDisable(GL_LIGHTING);
- break;
- case XK_F: case XK_f:
- useFog = !useFog;
- useFog ? glEnable(GL_FOG) : glDisable(GL_FOG);
- break;
- case XK_1:
- glFogf(GL_FOG_MODE, GL_LINEAR);
- break;
- case XK_2:
- glFogf(GL_FOG_MODE, GL_EXP);
- break;
- case XK_3:
- glFogf(GL_FOG_MODE, GL_EXP2);
- break;
- default:
- break;
- }
- }
- break;
- case ConfigureNotify:
- width = event.xconfigure.width;
- height = event.xconfigure.height;
- glViewport(0, 0, width, height);
- break;
- default:
- break;
- }
- }
-
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-
- glPushMatrix();
- glTranslatef(0.0, -1.5, 0.0);
- glRotatef(-90.0, 1, 0, 0);
- glScalef(2.0, 2.0, 2.0);
-
- drawCheck(6, 6, BLUE, YELLOW); /* draw ground */
- glPopMatrix();
-
- glPushMatrix();
- glTranslatef(0.0, 0.0, -0.9);
- glScalef(2.0, 2.0, 2.0);
-
- drawCheck(6, 6, BLUE, YELLOW); /* draw back */
- glPopMatrix();
-
- glPushMatrix();
- glTranslatef(0.0, 0.2, 0.0);
- glScalef(0.3, 0.3, 0.3);
- glRotatef((360.0 / (30 * 1)) * i, 1, 0, 0);
- glRotatef((360.0 / (30 * 2)) * i, 0, 1, 0);
- glRotatef((360.0 / (30 * 4)) * i, 0, 0, 1);
- glScalef(1.0, 2.0, 1.0);
- glGetFloatv(GL_MODELVIEW_MATRIX, (GLfloat *)cubeXform);
-
- drawCube(RED); /* draw cube */
- glPopMatrix();
-
- glDepthMask(GL_FALSE);
- if (useRGB) {
- glEnable(GL_BLEND);
- } else {
- glEnable(GL_POLYGON_STIPPLE);
- }
- if (useFog) {
- glDisable(GL_FOG);
- }
-
- glPushMatrix();
- myShadowMatrix(groundPlane, lightPos);
- glTranslatef(0.0, 0.0, 2.0);
- glMultMatrixf((const GLfloat *) cubeXform);
-
- drawCube(BLACK); /* draw ground shadow */
- glPopMatrix();
-
- glPushMatrix();
- myShadowMatrix(backPlane, lightPos);
- glTranslatef(0.0, 0.0, 2.0);
- glMultMatrixf((const GLfloat *) cubeXform);
-
- drawCube(BLACK); /* draw back shadow */
- glPopMatrix();
-
- glDepthMask(GL_TRUE);
- if (useRGB) {
- glDisable(GL_BLEND);
- } else {
- glDisable(GL_POLYGON_STIPPLE);
- }
- if (useFog) {
- glEnable(GL_FOG);
- }
-
- glXSwapBuffers(dpy, win);
- }
- }
- }
-
-